package com.eshop.dao;

import com.eshop.dao.provider.OrderInfoDynSqlProvider;
import com.eshop.pojo.OrderDetail;
import com.eshop.pojo.OrderInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

public interface OrderInfoDao { //订单信息
        @SelectProvider(type = OrderInfoDynSqlProvider.class,method = "selectByPage")
        @Results({
                @Result(property = "user" ,column = "uid" ,one = @One(select = "com.eshop.dao.UserInfoDao.getUserInfoById",fetchType = FetchType.EAGER))
        })
    List<OrderInfo> selectByPage(Map<String,Object> param);//分页查询订单信息

        @SelectProvider(type = OrderInfoDynSqlProvider.class,method = "count")
    int count(Map<String,Object> param);//根据参数查询订单总数

        @Insert("insert into order_info(uid, status, ordertime, orderprice) " +
                "VALUES (#{uid},#{status},#{ordertime},#{orderprice})")
        @Options(useGeneratedKeys = true)
    int saveOderInfo(OrderInfo orderInfo);//保存订单信息

        @Insert("insert into order_detail(oid, pid, num) VALUES (#{oid}, #{pid}, #{num})")
        @Options(useGeneratedKeys = true)
    int saveOrderDetail(OrderDetail detail);//保存订单明细

        @Select("select * from order_info where id=#{id};")
        @Results({
                @Result(property = "user" ,column = "uid" ,one = @One(select = "com.eshop.dao.UserInfoDao.getUserInfoById",fetchType = FetchType.EAGER))
        })
    OrderInfo selectOrderInfoById(int id);//根据订单号获取订单信息

        @Select("select * from order_detail where oid = #{oid}")
        @Results({
                @Result(property = "pi" ,column = "pid",one = @One(select = "com.eshop.dao.ProductInfoDao.selectById",fetchType = FetchType.EAGER))
        })
    List<OrderDetail> selectOrderDetailByOid(int oid);//根据订单号获取订单明细

        @Delete("delete  from order_info where id=#{id}")
    int deleteOrderInfo(int id);//根据订单号删除订单信息

        @Delete("delete from order_detail where oid=#{oid}")
    int deleteOrderDetail(int oid);//根据订单号删除订单明细
}
